<!DOCTYPE HTML><html>
<head>
<? echo $h->meta($title, $kwd, $dpn); ?>
<? require_once("lib.php"); ?>
<script src="<?=$ecom?>/js/jquery.validate.js" type="text/javascript"></script>
<script src="<?=$ecom?>/js/jquery.metadata.js" type="text/javascript"></script>
</head>

<body>
<? include_once("header.php"); ?>
<div id="wrap">
	<div id="main">
		<ul class="flow_step">
			<li><?=WEB_MY_CART?></li>
			<li class="step1"><?=WEB_FILL_CHECK_ORDER?></li>
			<li><?=WEB_SUCCESS_SUBMIT_ORDER?></li>
		<div class="clear"></div>
		</ul><!--flow_step end -->
		<? 
		// 若有实体商品, 加载之
		if(! $are_virtual){
		?>
		<div id="addr_box">
			<div id="order_title"><?=WEB_ADDRESS_BOOK?></div>
			<ul class="order_address_list">
				<?
				// 游客的地址处理方式不同, 请留意
				$html_address=''; $str='';
				foreach($arr_address as $val){
					$temid=$val['id'];
					// 获取默认值
					$check=''; $css=' ';
					if($checked_address_id==$temid) { $check=' checked '; $css=' selected '; }

					$tem_country=OVERSEA?$country->get_name($val['country_id'],$lang):'';
					$tem_province=$val['province_id']==0?'':$province->get_name($val['province_id'],$lang);
					$tem_city=$val['city_id']==0?'':$city->get_name($val['city_id'],$lang);
					$tem_county=$val['county_id']==0?'':$county->get_name($val['county_id'],$lang);

					$str.='<li class=" '.$css.' delete'.$val['id'].'">
				<div class="order_address_info">
					<span class="c1 radio_wrap"><input onclick="$(\'.address_book_id\').val(\''.$temid.'\');goto(\'order.php?address_id='.$temid.'\')" '.$check.' id="radio'.$temid.'" type="radio" name="address_id"></input></span>
					<label class="radio_desp" for="radio'.$temid.'">
					<span class="c3"> &nbsp; '.$tem_country.' '.$tem_province.' '.$tem_city.' '.$tem_county.' '.$val['street'].', &nbsp; '.$val['contact_name'].' '.$val['mobile'].'</span></label>
					<span class="order_address_editor"><a href="address_book.php?refer=order&do=update&id='.$val['id'].'">'.WEB_EDIT.'</a><a onclick="ajax_delete_address(\'address_book\',\''.$val['id'].'\')">'.WEB_DELETE.'</a></span>
				</div>
				<div class="clear"></div>
				</li>';
				}
				$html_address=$str;
				echo $html_address;
				?>
				</ul>
		<div class="order_address_other"><a href="address_book.php?souce=order#add">+ <?=WEB_ADD_ADDRESS?></a></div>
		<script type="text/javascript">
			function ajax_delete_address(table,id){
				if(!confirm("<?=WEB_JS_CONFIRM_DELETE?>")) return false;
				var div = '.delete'+id;$.get("ajax_delete.php","table="+table+"&id="+id, function(msg){
					if(msg=='1'){
					top.location.reload();}});
			}
		</script>
		</div><!--addr_box end-->
		<? } ?>

		<?	echo $h->form('checkout.php',0,'order_form');
			$key=md5('ecomgear'.date('Ymd'));
			echo $h->hidden('key',$key);
			// 表单 - 地址部分
			echo $h->hidden('address_book_id',$checked_address_id,'address_book_id');
			echo $h->hidden('email',$email);
		?>

		<div id="pay_box">
			<div id="order_title"><?=WEB_PAYMENT_METHOD?></div>
			<div class="order_payment_area">
				<?
					$str=''; $str2=''; $k=0;
					foreach($arr_payment as $key=>$row){
						$checked='';
						if($k==0)$checked=' checked ';
						

						if(!empty($row['pic'])) $str.='<li>
					<div class="payment_area"><input '.$checked.' id="pay_'.$k.'" class="radio" type="radio" name="payment_method" value="'.$row['id'].'"></input>
						<label class="vam" for="pay_'.$k.'"><img src="upload/'.$row['pic'].'" height="36" /></label>
					</div>
				</li>';
						else $str2.='<li>
					<div class="payment_area">
						<input id="pay_'.$k.'" class="radio" type="radio" name="payment_method" value="'.$row['id'].'"></input>
						<label class="vam" for="pay_'.$k.'">'.$row['name_'.$lang].'</label>
					</div>
				</li>';
						$k++;
					}
				?>
				<? if($str!=''){ ?>
				<div class="explain"><b><?=WEB_ONLINE_PAYMENT?>： </b></div>
				<ul class="payment_bank_list">
					<? echo $str ?>
				</ul><!--payment_bank_list end--><div class="clear"></div>
				<? } ?>
				<? if($str2!=''){ ?>
				<div class="explain"><b><?=WEB_OTHER_METHOD?>： </b></div>
				<ul class="payment_bank_list">
					<? echo $str2 ?>
				</ul><!--payment_bank_list end--><div class="clear"></div>
				<? } ?>
			</div><!--order_payment_area end-->
		</div><!--pay_box end-->

		<? $nada=''; if($lang_id != 2) $nada='hide'; ?>
		<div id="pay_box" class="<?=$nada?>">
			<div id="order_title"><?=WEB_INVOICE_INFO?></div>
			<div class="order_invoice_area">
				<table border="0" cellpadding="0" cellspacing="0">
            		<tbody>
                	<tr>
                		<td><input type="checkbox" name="titleType" class="radio vam check_tax" id="titleType-per" value="1" onclick="cal_with_tax();"><label class="vam" for="titleType-per"><?=WEB_INVOICE_NEED?></label></td>
                	</tr>
                	<tr class="invoicer hide">
            		<td><label class="vam" for="titleType-com"><?=WEB_INVOICE_HEADER?>: </label>&nbsp;&nbsp;
					<div class="inline-block"><input type="text" name="invoice_header" id="invoiceTitle-com" class="text vam span_400" /></div></td>
                    	</tr>
                	</tbody>
            	</table>
			</div><!--order_invoice_area end-->
		</div><!--pay_box end-->
		<? 
		// 若有实体商品, 加载之
		if(! $are_virtual){
		?>
		<div id="pay_box">
			<div id="order_title"><?=WEB_SHIPMENT_METHOD?></div>
			<ul class="delivery_list">
				<?
				$str='';
				$k=0;
				foreach($arr_shipment_final as $row){
					$checked='';
					if($k==0)$checked=' checked ';
					$str.='<li>
				<div class="payment_area shipment'.$k.'"><input onclick="cal_price('.$k.')" '.$checked.' id="shipment_'.$k.'" class="radio" type="radio" name="shipment_method" value="'.$row['id'].'" />
					<label class="vam" for="shipment_'.$k.'">'.$row['name_'.$lang].'<span class="vam gray">'.WEB_SHIPMENT_FEE.' &nbsp; '.$currency_sign.'<em class="a_shipment_cost">'.$row['shipment_cost'].'</em> (<em class="gray">'.$total_weight.'g</em>)</label>
					</div>
				</li>';
					$k++;
				}
				if($k==0) $str='<pp class="red">'.WEB_CANNOT_SHIP.'</p>';
				echo $str;
			?>
			</ul>
            <div class="tright hide"><br /><span class="icon-over vam">买满200元免运费. &nbsp; </span></div>
		</div><!--pay_box end-->
		<? } ?>
		<div id="pay_box">
			<div id="order_title"><?=WEB_ITEM_LIST?></div>
			<table class="table_cart" cellpadding="0" cellspacing="0">
			<thead class="list_cart">
				<tr>
				<th class="textcenter" width="360"><?=WEB_ITEM?></th>
				<th><?=WEB_UNIT_PRICE?></th>
				<th><?=WEB_PURCHASE_QUANTITY?></th>
				<th><?=WEB_SUBTOTAL?></th>
				</tr>
			</thead>
			<tbody>
			<?	$str='';
				$order_price=0;
				foreach($cart as $row){
					$tem_product=$product->get_row($row['pid']);
					$tem_price=round($tem_product['price']*$currency_rate,2);
					$tem_stock=$tem_product['stock'];

					$tem_pic=$tem_product['small_pic'];
					$tem_link='product-'.$row['pid'].'.html';
					$tem_name=str_cut($tem_product['name_'.$lang],PRODUCT_TITLE_DISPLAY_LENGTH,$lang);
					$tem_qty=$row['qty'];


					// variation
					$str_var='';
					if($row['var']){
						$tem_var=$product_variation->get_row($row['var']);
						$tem_price=round($tem_var['price']*$currency_rate,2); // var
						$tem_stock=$tem_var['stock'];  // var
						if($tem_var['size']) $str_var.=$option_label[2].': '.$option_value[$tem_var['size']].' &nbsp; ';
						if($tem_var['color']) $str_var.=$option_label[1].': '.$option_value[$tem_var['color']].' &nbsp; ';
						if($tem_var['other1']) $str_var.=$option_label[3].': '.$option_value[$tem_var['other1']].' &nbsp; ';
						if($tem_var['other2']) $str_var.=$option_label[4].': '.$option_value[$tem_var['other2']].' &nbsp; ';
					}
					$has_stock=$tem_stock>=$tem_qty?1:0;
					
					if($has_stock){
						$tem_total=$tem_qty*$tem_price;
						$order_price+=$tem_total;
						$str.='<tr>
					<td><div class="goods"><span class="image"><a href="'.$tem_link.'" target="_blank"><img src="'.PRODUCT_PIC_HOST.$tem_pic.'"/></a></span><div class="name"><a href="'.$tem_link.'" target="_blank">'.$tem_name.'</a><br /><br /><span class="gray">'.$str_var.'</span></div><div class="clear"></div></div></td>
					<td><strong class="price red">'.$currency_sign.' '.$tem_price.'</strong></td>
					<td>'.$tem_qty.'</td>
					<td><strong class="price">'.$currency_sign.' '.$tem_total.'</strong></td>
					</tr>';
					}
				}
				echo $str;
			?>
			</tbody>
			<? if($can_buy){ ?>
			<tfoot>
				<tr>
				<th colspan="4">
					<?
						// 表单 - 金额部分
						$with_tax=0;
						$tax=0;
						$total_price=$order_price+$shipment_fee;
						$deposit=$total_price;
						echo $h->hidden('order_price',$order_price,'order_price');
						echo $h->hidden('total_price',$total_price,'total_price');
						echo $h->hidden('shipment_cost',$shipment_fee,'shipment_cost');
						echo $h->hidden('customer_id',$customer_id,'customer_id');
						echo $h->hidden('currency_id',$currency_id,'currency_id');
						echo $h->hidden('is_virtual',$are_virtual,'');
						echo $h->hidden('with_tax',$with_tax,'with_tax');
						echo $h->hidden('tax',$tax,'input_tax');
					?>
					<div class="customer_remark">
						<div><?=WEB_ORDER_REMARK?>: &nbsp; <input type="text" name="customer_remark" id="customer_remark" class="" maxlength="32" /></div>
					</div>
					<div class="price_check_box inherit">
						<div class="price_list">
							<div class="total">
							<p><span class="t"><?=WEB_TOTAL_FOR_ITEMS?>：</span><span class="txt price"><? echo $currency_sign.' '.$order_price ?></span></p>
							<? 
							$nada=''; if($are_virtual) $nada=' class="hide" ';
							?>
							<p <?=$nada?>><span class="t"><?=WEB_SHIPMENT_FEE?>：</span><span class="txt price"><? echo $currency_sign.'<span class="span_shipment_cost">'.$shipment_fee.'</span>' ?></span></p>
							<p id="div_tax" class="hide"><span class="t"><?=WEB_TAX?>：</span><span class="txt price"><? echo $currency_sign.'<span class="span_tax">'.$tax.'</span>' ?></span></p>
							<p><span class="t all"><?=WEB_ORDER_TOTAL?>：</span> <span class="txt finalprice"><? echo $currency_sign.' <span class="span_total_price">'.$total_price.'</span>'; ?></span></p>
							<p><span class="t"><?=WEB_SHOULD_PAY?>：</span> <span class="txt"><? echo $currency_sign.' <span class="span_deposit">'.$deposit.'</span>'; ?></span></p>
							</div>
							<div class="cart_buttom">
								<a class="payment" onclick="order_submit()"><?=WEB_SUBMIT_ORDER?></a>
							</div>
						</div>
					<div class="clear"></div>
					</div>
					<div class="clear"></div>
                    <div class="privilege customer_remark"><?=WEB_DISCOUNT_COUPON?></div>
                    <div class="privilege customer_remark">

                        我的优惠券
                    </div>
				</th>
				</tr>
			</tfoot>
			<? } ?>
		</table>
		</div><!--pay_box end-->
		<? echo $h->former(); ?>
	</div><!--main end-->
</div><!--wrap end-->
<? include("footer.php"); ?>
<script type="text/javascript">
	var tax_rate=<?=TAX_RATE?>;
// 订单总额 = (商品价格 + 税费) * 预付款比例 + 运费
	function cal_price(id){ // 根据运费
		var div='.shipment'+id;
		var shipment_cost=parseFloat($(div).find('em').html()).toFixed(2); // 运费
		var tax=parseFloat($('.input_tax').val()).toFixed(2); // 税
		var order_price=parseFloat($('.order_price').val()).toFixed(2);

		var total_price=parseFloat(shipment_cost*1+1*order_price+tax*1).toFixed(2);
		$('.span_shipment_cost').html(shipment_cost);
		$('.span_total_price').html(total_price);
		$('.shipment_cost').val(shipment_cost);
		$('.total_price').val(total_price);

	}
	function cal_with_tax(){
		$('.invoicer').toggleClass('hide');
		var shipment_cost=parseFloat($('.shipment_cost').val()).toFixed(2); // 运费
		var order_price=parseFloat($('.order_price').val()).toFixed(2);

		if($('.check_tax').is(":checked")){
			var tax= parseFloat(order_price * tax_rate).toFixed(2); // 税
			var total_price=parseFloat(shipment_cost*1+1*order_price+tax*1).toFixed(2);
			$('.span_tax').html(tax);
			$('.total_price').val(total_price);
			$('.input_tax').val(tax);
			$('.with_tax').val(1);
			$('.span_total_price').html(total_price);
			$('#div_tax').removeClass('hide');
		}
		else {
			var tax= 0; // 税
			var total_price=parseFloat(shipment_cost*1+1*order_price+tax*1).toFixed(2);
			$('.span_tax').html(tax);
			$('.total_price').val(total_price);
			$('.input_tax').val(tax);
			$('.with_tax').val(0);
			$('.span_total_price').html(total_price);
			$('#div_tax').addClass('hide');
		}
	}
	function cal_with_deposit(rate){
		var order_price=parseFloat($('.order_price').val()).toFixed(2);

		var tax= parseFloat(order_price * tax_rate).toFixed(2); // 税
		var shipment_cost=parseFloat($('.shipment_cost').val()).toFixed(2); // 运费
	}
</script>
</body>
</html>